package cn.toma.config.web.utli;

import cn.toma.config.authentication.JWTUtil;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: zqx
 * @Date: 2019-07-24 16:54
 * @Description:
 */
public class BaseController
{
	protected Map<String, Object> getDataTable(PageInfo<?> pageInfo)
	{
		Map<String, Object> rspData = new HashMap<>(8);
		rspData.put("rows", pageInfo.getList());
		rspData.put("total", pageInfo.getTotal());
		return rspData;
	}

	public String getOnlineUser()
	{
		String token = (String) SecurityUtils.getSubject().getPrincipal();
		String username = "";
		if (StringUtils.isNotBlank(token)) {
			username = JWTUtil.getUsername(token);
		}
		return username;
	}


}
